<template>
	<view class="container">
		<view class="user-section">
			<view class="user-info-box">
				<view class="portrait-box">
					<image class="portrait"
						:src="userInfo.user_info.avatar || 'https://shanerxiang.com/uploads/adm_images/missing-face.png'"
						v-if="userInfo"></image>
					<image class="portrait" src="https://shanerxiang.com/uploads/adm_images/missing-face.png" v-else>
					</image>
				</view>
				<view>
					<view v-if="userInfo.user_info && userInfo.user_info.mobile"
						style="display: flex;flex-direction: column;">
						<text class="username">{{userInfo.user_info.nickname}}</text>
						<view style="margin-left: 20rpx;display: flex;align-items: center;margin-top: 10rpx;" @click="navTo('/pages/user/userinfo')">
							<image src="/static/temp/gx.png"
								style="height: 32rpx;width: 32rpx;"></image>
							<text style="font-size: 28rpx;color: #999999;">点击更新信息</text>
						</view>

					</view>
					<view class="username-no" v-else @click="navTo('/pages/public/wxLogin')">立即登录</view>
				</view>
				<view class="entrance" @click="toShop()"><text>进店</text><text class="cell-icon yticon icon-you"	style="color: #23A948;font-size: 24rpx;"></text></view>
			</view>

		</view>

		<view class="cover-container">

			<view class="tj-sction">
				<view class="tj-item" @click="navTo('/pages/user/statics?tab_menu=0',2)">
					<text class="num">￥{{total_price}}</text>
					<text>今日订单金额</text>
				</view>
				<view style="display: flex;align-items: center;color: #E0E0E0;">|</view>
				<view class="tj-item" @click="navTo('/pages/user/statics?tab_menu=1',2)">
					<text class="num">{{total_num}}</text>
					<text>今日订单销量</text>
				</view>

			</view>

			<view class="history-section icon">
				<view class="tab-menu" @click="navTo('/pages/public/help',2)" style="border-bottom: 1px solid rgba(18,17,42,0.07);"><view style="flex: 1;">帮助中心</view> <text class="cell-icon yticon icon-you"></text></view>
				<view class="tab-menu">
					<view v-if="hasLogin" style="flex: 1;">联系客服<button open-type="contact"></button></view><view v-else style="flex: 1;" @click="navTo('/pages/public/wxLogin')">联系客服</view> <text class="cell-icon yticon icon-you"></text>
				</view>
			</view>
		</view>

		<view class="site">
			<view class="site-detail">
				<image src="/static/temp/kt.png" style="width: 48rpx;height: 48rpx;"></image>
				<text style="padding: 0rpx 10rpx;color: #333333;font-size: 28rpx;">好团团接龙</text>
			</view>
			<view style="color: #999999;font-size: 28rpx;">一款快捷好用的团购接龙工具</view>
		</view>


	</view>
</template>
<script>
	import listCell from '@/components/mix-list-cell';
	import Api from '@/common/api';
	import {
		mapState,
		mapMutations
	} from 'vuex';

	export default {
		
		components: {
			listCell
		},
		data() {
			return {
				total_price:'0.00',
				total_num:0
			}
		},
		onLoad() {
			
		},
		onTabItemTap(item) {
		  let num = uni.getStorageSync('remind')||1;
		  let editDrag = uni.getStorageSync('edit_drag')||'';
				if(editDrag!='' && num<=1){
					uni.showModal({
						content:'需要保存编辑的接龙信息吗?',
						success:(async (rel)=>{
							if(rel.cancel){
								uni.removeStorage({
									key: 'edit_drag'  
								});
							}
						})
					})
				}
			num++;
			uni.setStorage({
				key:'remind',
				data:num
			})
		},
		computed: {
			...mapState(['hasLogin', 'userInfo']),
		},
		onShow() {
			this.loadStatics();
		},
		onShareAppMessage(){
			return {
				title:'好团团臻选',
				path:'/pages/index/index',
			}
		},
		onShareTimeline(){
			return{
				title:'好团团臻选',
				path:'/pages/index/index'
			}
		},
		methods: {
			...mapMutations(['logout']),
			/**
			 * 统一跳转接口,拦截未登录路由
			 * navigator标签现在默认没有转场动画，所以用view
			 */
			navTo(url,t=1) {
				if(t==1){
					if (!this.hasLogin) {
						// #ifdef MP
						url = '/pages/public/wxLogin';
						// #endif
						// #ifndef MP
						url = '/pages/public/login';
						// #endif
					}
					
				}
				uni.navigateTo({
					url
				})
			},
			async loadStatics(){
				let data = await Api.apiCall('get',Api.apiName.user_statics,{});
				if(!data){
					return;
				}
				let res = data.data.statics;
				this.total_price=res.total_price;
				this.total_num = res.total_num;
			},
			toShop(){
				if(this.hasLogin){
					if(this.userInfo.user_info.can_publish==1){
						uni.switchTab({
							url:'/pages/index/create'
						})
					}else{
						uni.navigateTo({
							url:'/pages/index/lists?id='+this.userInfo.user_info.id
						})
					}
				}else{
					uni.navigateTo({
						url:'/pages/public/wxLogin'
					})
				}
			},

			//退出登录
			toLogout() {
				uni.showModal({
					content: '确定要退出登录么',
					success: (e) => {
						if (e.confirm) {
							this.logout();
							setTimeout(() => {
								uni.navigateBack();
							}, 200)
						}
					}
				});
			},

		}
	}
</script>
<style lang='scss'>
	page {
		background: #f5f5f5;
	}

	%flex-center {
		display: flex;
		flex-direction: column;
		justify-content: center;
		align-items: center;
	}

	%section {
		display: flex;
		justify-content: space-around;
		align-content: center;
		background: #fff;
		border-radius: 16upx;
	}

	.user-section {
		height: 500upx;
		padding: 100upx 30upx 0;
		position: relative;
		background: linear-gradient(to bottom, rgba(35, 169, 72, 0.5), rgba(35, 169, 72, 0.15));
		border-radius: 15px;
		top: -15px;

	}

	.user-info-box {
		height: 180upx;
		display: flex;
		/* align-items:center; */
		position: relative;
		z-index: 1;
		margin-top: 150rpx;

		.portrait {
			width: 120upx;
			height: 120upx;
			border-radius: 50%;
		}

		.username {
			font-size: $font-lg + 4upx;
			color: $font-color-dark;
			margin-left: 20upx;
			font-weight: 600;
			float: left;
			margin-top: 10rpx;
		}

		.username-no {
			font-size: $font-lg + 6upx;
			/* color: $font-color-dark; */
			color: #3D592F;
			margin-left: 20upx;
			padding: 0 38rpx;
			margin: 30upx;
			border-radius: 100px;
			height: 76rpx;
			line-height: 76rpx;
			font-size: 30rpx;
			background: #f9f2f4;
			box-shadow: 1px 2px 5px rgba(218, 177, 185, 0.72);
		}
	}

	.info-box {
		position: absolute;
		top: 56rpx;
		left: 64px
	}

	.logout-v {
		position: absolute;
		top: 52px;
		left: 76px;
	}

	.logout-img {
		width: 13px;
		height: 13px;
		position: absolute;
		top: 6px;
		left: 68px;
	}

	.log-out {
		background: rgba(61, 89, 47, 0.3);
		border-radius: 12px;
		width: 136px;
		height: 36px;
		padding: 3px 26px 3px 14px;
		color: white;
		font-size: 12px;

	}


	.cover-container {
		margin-top: -50upx;
		padding: 0 30upx;
		position: relative;
		background: #f5f5f5;
		padding-bottom: 20upx;

	}

	.tj-sction {
		@extend %section;
		position: relative;
		top: -60rpx;

		.tj-item {
			@extend %flex-center;
			flex-direction: column;
			height: 140upx;
			font-size: $font-sm;
			color: #000000;
		}

		.num {
			font-size: $font-lg + 4upx;
			color: $font-color-dark;
			margin-bottom: 8upx;
		}
	}

	.history-section {
		background: #FFFFFF;
		border-radius: 16upx;
		margin-top: -32rpx;

		.sec-header {
			display: flex;
			align-items: center;
			font-size: $font-base;
			color: $font-color-dark;
			line-height: 40upx;
			margin-left: 30upx;

			.yticon {
				font-size: 44upx;
				color: #5eba8f;
				margin-right: 16upx;
				line-height: 40upx;
			}
		}

		.h-list {
			white-space: nowrap;
			padding: 30upx 30upx 0;

			image {
				display: inline-block;
				width: 160upx;
				height: 160upx;
				margin-right: 20upx;
				border-radius: 10upx;
			}
		}

		.content {
			margin-top: 8px;
			background: white;
			border-radius: 6px;
		}
	}

	.entrance {
		border: 1px solid #23A948;
		border-radius: 28rpx;
		padding: 2rpx 26rpx;
		height: 48rpx;
		font-size: 24rpx;
		position: absolute;
		right: 20rpx;
		bottom: 70rpx;
		display: flex;
		align-items: center;
		color: #23A948;
	}

	.site {
		margin: 30rpx;
		display: flex;
		align-items: center;
		flex-direction: column;
	}

	.site-detail {
		display: flex;
		align-items: center;
		padding: 30rpx;
	}

	.tab-menu {
		display: flex;
		padding: 30rpx 0rpx;
		align-items: center;
		margin: 0rpx 30rpx;
	}
	button{
		background-color: transparent !important;
		margin-top: -46rpx;
		height: 64rpx !important;
		line-height: 64rpx !important;
	}
	button::after{
		background-color: transparent !important;
		border: none !important;
	}
</style>